package com.example.examapp;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

/**
 * 找工作
 * @author FenGKun
 *
 */
public class FindWorkFragement extends Fragment {

    /** 找工作 */
    private View m_vFindWorkFragment;
    /** 姓名 */
    private EditText m_etName;
    /** 电话 */
    private EditText m_etPhone;
    /** 发布 */
    private Button m_btnCommit;
    /** 重置 */
    private Button m_btnReset;
    /** 下拉列表 */
    private Spinner m_spType;
    private ArrayAdapter<String> adapter;
    /** 选项 */
    private String[] types = new String[] {"医   生","工   人","教   师","销   售","服   务"};

    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        m_vFindWorkFragment = inflater.inflate(R.layout.activity_find_work_fragement, container,false);

        // 初始化变量
        initUi();
        return m_vFindWorkFragment;
    }

    /**
     * 初始化变量
     */
    private void initUi() {
        // 姓名
        m_etName = (EditText) m_vFindWorkFragment.findViewById(R.id.etName);
        // 电话
        m_etPhone = (EditText) m_vFindWorkFragment.findViewById(R.id.etPhone);
        // 发布
        m_btnCommit = (Button) m_vFindWorkFragment.findViewById(R.id.btnCommit);
        m_btnCommit.setOnClickListener(commit);
        // 重置
        m_btnReset = (Button) m_vFindWorkFragment.findViewById(R.id.btnReset);
        m_btnReset.setOnClickListener(reset);
        // 下拉列表
        m_spType = (Spinner) m_vFindWorkFragment.findViewById(R.id.spType);
        // 定义适配器
        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, types);
        //设置下拉列表的风格
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //将adapter 添加到spinner中
        m_spType.setAdapter(adapter);
        //添加事件Spinner事件监听
        m_spType.setOnItemSelectedListener( new itemSelectedListener());
        m_spType.setVisibility(View.VISIBLE);
        m_spType.setSelection(0, true);
    }

    /**
     * spinner监听类
     */
    private class itemSelectedListener implements OnItemSelectedListener{

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                                   int position, long id) {
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub

        }

    }

    /**
     * 发布事件
     */
    private View.OnClickListener commit = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getActivity(), "发布成功！请静静等待...", Toast.LENGTH_SHORT).show();
        }
    };

    /**
     * 重置事件
     */
    private View.OnClickListener reset = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            m_etName.setText("");
            m_etPhone.setText("");
            m_spType.setSelection(0, true);
        }
    };


}